/**
 * @description 本文件中内容为类型判断.
 */
const toString = Object.prototype.toString;

/**
 * @description 判断是否为某个类型.
 * @param val 传入的对象.
 * @param type 类型名称.
 */
export function is(val: unknown, type: string) {
  return toString.call(val) === `[object ${type}]`;
}

/**
 * @description:  是否为字符串
 */
export function isString(val: unknown): val is string {
  return is(val, "String");
}

/**
 * @description: 是否为对象
 */
export const isObject = (val: any): val is Record<any, any> => {
  return val !== null && is(val, "Object");
};

/**
 * 如有必要, 则需判断表达式是否为函数.
 * @param val
 */
// export function isFunction<T = Function>(val: unknown): val is T {
//   return is(val, "Function");
// }

/**
 * @description 判断传入的字符串是否为url连接
 * @param url 传入字符串
 */
export function isUrl(url: string) {
  return /(^http|https:\/\/)/g.test(url);
}
